package com.satis.compose.get.example.pages

import androidx.compose.animation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.viewmodel.compose.viewModel
import com.satis.compose.get.example.ui.theme.ComposeGetTheme
import com.satis.compose.get.example.viewmodel.MainViewMode
import com.satis.compose.get.widget.GetPage
import com.satis.compose.get.annotation.PageRoute
import com.satis.compose.get.widget.GetBottomBar
import com.satis.compose.get.widget.GetBottomBarItem

/**
 * @author sunshaobei on 2022/9/6
 */

@PageRoute("Main")
@Composable
fun MainPage() {
    val viewModel: MainViewMode = viewModel()
    val uiState = viewModel.uiState
    var selectedItem by uiState.selectedItem.observeAsState() as MutableState
    val items = arrayOf(
        GetBottomBarItem("基础",1) { ComposePage() },
        GetBottomBarItem("Api",1) { GetApiPage() },
        GetBottomBarItem("mvi",1) { TestMVIPage() },
        GetBottomBarItem("home",1) { HomePage() },
        GetBottomBarItem("text",1) { TextPage() },

        )
    GetPage(
        statusBarColor = Color.Transparent,
        navigationBarColor = Color.Red,
        darkIcons = true,
        bottomBar = {
            GetBottomBar(backgroundColor = Color.Red, unselectedContentColor = Color.LightGray, selectedItem = selectedItem!!, items = items){
                uiState.selectedItem.value = it
            }
        }
    ) {
       items[selectedItem!!].body.invoke()
    }
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    ComposeGetTheme {
        MainPage()
    }
}